﻿<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="global.Constants"%>
    <%@page import="util.ServletHelp"%>
 <%@page import="com.aiflow.Action.DepartmentAction"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
	<%
	
		String baseUrl = request.getContextPath();
 
	%>
	<script type="text/javascript">
	Ext.chart.Chart.CHART_URL = '<%=baseUrl %>/js/ext-3.3.0/resources/charts.swf';
	    //这里的全局是为了修改之后的刷新
	    var heraldRecordListGrid;
	    var heraldRecordListStore;
		$(document).ready(function(){
			 // 全局参数
			var baseParams = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			var EXT_QUERY_TIME_OUT = 1200000;
     
		   

			// 传报数据源  userName,u.telep ,d.name as targetName
		    heraldRecordListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/heraldRecord_findRecord.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        totalProperty: 'results',
		        fields: ['snumbe','Alarm_id','Region_name','Alarm_pro','Dn','Dn_type','Alarm_title','Alarm_time','alarm_status','send'],
		        baseParams: baseParams,
		        autoLoad: true,
				listeners : {  
          load : function() {  
              isDetailReady = true;// 查询置换标志为已查过   
            }  
            }  
		    });
		    
		      // 区域  数据源  getDepartmentCombo("1")  湖北下级
	          var regionStore = new Ext.data.ArrayStore({  
	            fields : ['region_id', 'region_name'],  
	            data : <%=DepartmentAction.getDepartmentNameCombo("1")%>,
	            sortInfo: {field: "region_id", direction: "ASC"}
	        });
		    
	        var recodeStore = new Ext.data.ArrayStore({  
                    fields : ['status', 'statusName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.ALARM_SEND_MAP, null)%>,
		            sortInfo: {field: "status", direction: "ASC"}
	        });
	       
	        	        var heraldRecordStore = new Ext.data.ArrayStore({  
                    fields : ['heraldRecord', 'heraldRecordName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.ALARM_SEND_MAP, null)%>,
		            sortInfo: {field: "heraldRecord", direction: "ASC"}
	        });
	     
			
			 var sendStatusCombo = new Ext.form.ComboBox({
				id :'sendStatusCombo', 
			    	hiddenName: 'alarmStatus',
				triggerAction: 'all', 
				typeAhead: true, 
				store: recodeStore, 
				mode : 'local',
				valueField: 'status', 
				displayField: 'statusName', 
				editable: true, 
				lazyRender: true,
				allowBlank:false
			});
			
			var heraldCombo = new Ext.form.ComboBox({
				id :'heraldCombo', 
				//   hiddenName: 'heraldCombo',
				triggerAction: 'all', 
				typeAhead: true, 
				store: heraldRecordStore, 
				mode : 'local',
				valueField: 'heraldRecord', 
				displayField: 'heraldRecordName', 
				editable: true, 
				width:130,
				lazyRender: true,
				allowBlank:true
			});
			  
		
		 
				   	    // 工具栏
		   var heraldRecordListToolbar = new Ext.Toolbar({
		    	renderTo: 'heraldRecordListToolBarDiv',
		    	items: [
					new Ext.Button({
					    id: 'recode-save-button',
					    text: '保存',
						iconCls: 'lightning_go'
					}),
						new Ext.Button({
					    id: 'recode-delete-button',
					    text: '删除',
						iconCls: 'lightning_delete'
					}),
					'-',
		             new Ext.Button({
					    id: 'recode-down-button',
					    text: '导出',
						iconCls: 'page_white_excel'
						
					}),
					'-','查询：','区域',
					{  
			                xtype:'combo',
			                id:'regionh',
			                hiddenName: 'region',
			                fieldLabel: '省市',
			                store: regionStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'region_id',
			                displayField: 'region_name',
			                allowBlank:true,
			                editable: false,
			                width: 130,
			                anchor:'98%'
			           },
			             '&nbsp;&nbsp;发送状态',
			              heraldCombo,
			                '-',
		             new Ext.Button({
					    id: 'herald-query-button',
					    text: '查询',
						iconCls: 'magnifier'
						
					})
				]
			});
 
			// 数据表格    dept_name spec
			var sm = new Ext.grid.CheckboxSelectionModel();
			heraldRecordListGrid = new Ext.grid.EditorGridPanel({
				id: 'heraldRecordListGrid',
				renderTo: 'heraldRecordListGridDiv',
				border: false,
				stateful: true,
			    autoScroll: 'auto',
		        store: heraldRecordListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [   //id,Alarm_id,Region_name,Alarm_pro,Dn,Dn_type,Alarm_time,Org_severity
						sm,
						// new Ext.grid.RowNumberer({header:'№'}), sortnum
						{id:'snumbe',header: '告警流水号', width: 130, hidden: false, sortable: true , dataIndex: 'snumbe'},
						{id:'Alarm_id',header: '告警编号', width: 120, hidden: true, sortable: true , dataIndex: 'Alarm_id'},
						{id:'Alarm_time',header: '告警时间', width: 120, hidden: false, sortable: true , dataIndex: 'Alarm_time'},
			            {id:'Region_name',header: '地市', width: 70,hidden: false, sortable: true, dataIndex: 'Region_name'},
			            {id:'Alarm_title',header: '告警标题', width: 150,hidden: false, sortable: true, dataIndex: 'Alarm_title'},
			            {id:'Alarm_pro',header: '告警专业', width: 100,hidden: false, sortable: true, dataIndex: 'Alarm_pro'},
			            {id:'Dn',header: '网元名称', width: 250,hidden: false, sortable: true, dataIndex: 'Dn'},
                        {id:'Dn_type',header: '网元类型', width: 150,hidden: false, sortable: true, dataIndex: 'Dn_type'},
			            {id:'alarm_status',header: '告警状态', width:80,hidden: false, sortable: true, dataIndex: 'alarm_status'},
			            {id:'send',header: '发送状态', width: 80,hidden: false, sortable: true, dataIndex: 'send',editor: sendStatusCombo,renderer: function(value, cellmeta,record){return statusComboRenderer(value, cellmeta,record);}}
			             ]
		        }),
		        sm: sm,
		        columnLines: true,
		         bbar: new Ext.PagingToolbar({
					pageSize: <%=Constants.PAGE_SIZE %>,
					store: heraldRecordListStore,
					displayInfo: true,
					displayMsg: Anynote.PAGINGTOOLBAR_DISPLAYMSG,
					emptyMsg: Anynote.PAGINGTOOLBAR_EMPTYMSG,
					doLoad: function(start){
						baseParams.start = start;
						  var reg = Ext.getCmp("regionh").getValue();
			              var status = Ext.getCmp("heraldCombo").getValue();
			       baseParams.region = reg;
			       baseParams.sendStatus = status;
						this.store.load({params: baseParams});
					}
		        }),
		        listeners:{
		         rowdblclick:function(grid,rowIndex,event){
		          dx(grid,rowIndex,event);
		        }
		        },
		         clicksToEdit:1
		    });
		    
		    
		    

			// 设置Grid高度和宽度
		    Anynote.resizeGridTo("heraldRecordListGrid", 0, 56);
			 
			 
		    // 类型ComboBox设值  
 
			function statusComboRenderer(value, cellmeta,record){
				var index = recodeStore.find(Ext.getCmp('sendStatusCombo').valueField,value);
				var record = recodeStore.getAt(index);
				var displayText = "";
				
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.statusName;
				}
				return displayText;
			}
		})  
           
			      //    根据状态值 变颜色
		     heraldRecordListGrid.getStore().on('load',function(s,records){
              var girdcount=0;
                s.each(function(r){
                   
            if(r.get('send')=='1'){
              heraldRecordListGrid.getView().getCell(girdcount,10).style.backgroundColor='#00ff66';
            }else if(r.get('send')=='0'){
              heraldRecordListGrid.getView().getCell(girdcount,10).style.backgroundColor='#FFff00';
              } 
            girdcount=girdcount+1;
        });
         
      });      
      
      
      $("#recode-save-button").click(function(){
				var records = heraldRecordListStore.getModifiedRecords();
				// 验证
			
				if(records.length != 0){
					var params = {};
					params.jsonArr = Anynote.convertRecordsToJson(records);
					// 发送请求
					Anynote.ajaxRequest({
						baseUrl: '<%=baseUrl %>',
						baseParams: params,
						action: '${pageContext.request.contextPath}/heraldRecord_saveRecord.action',
						callback: function(jsonResult){
							  heraldRecordListGrid.getStore().reload();  
						},
						showWaiting: true,
						failureMsg: '保存失败.'
					});
				}
			});
			
			
			 $("#herald-query-button").click(function(){
			   var reg = Ext.getCmp("regionh").getValue();
			   var status = Ext.getCmp("heraldCombo").getValue();
			     var basePar  = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			       basePar.region = reg;
			       basePar.sendStatus = status;
			    heraldRecordListStore.reload({params:basePar});
			 })
		
				$("#recode-delete-button").click(function(){
				// 提交
				var recodes = heraldRecordListGrid.getSelectionModel().getSelections();
				if(recodes.length < 1){
					 Ext.Msg.alert("提示", "请至少选择一条数据.");
				}else{
				  var k = '';
				  var val = '';
				  for(var i = 0;i<recodes.length;i++){
				     k=recodes[i];
				        val += '\''+k.get("Alarm_id")+'\',';
				  }
				
				  Anynote.ajaxRequest({
								baseUrl: '<%=baseUrl %>',
							       baseParams: {alarmIds:val },
								action: '${pageContext.request.contextPath}/heraldRecord_deleteRecord.action',
								callback: function(jsonResult){
							
									heraldRecordListStore.reload();
								},
								showWaiting: true,
								failureMsg: '保存失败.'
							});
						   }
					     });
					     
					     
					     
					     
				  $("#recode-down-button").click(function(){   //   下载 
				  
				   var reg = Ext.getCmp("regionh").getValue();
			       var status = Ext.getCmp("heraldCombo").getValue();
			        window.location.href = "${pageContext.request.contextPath}/heraldRecord_down.action?region="+reg+"&sendStatus="+status;
				  })
				  
				  
				  
	  // 柱状图
	  // 拨打统计按钮
			function dx(grid,rowIndex,event){
		    var selectionModel = grid.getSelectionModel();    
            var record = selectionModel.getSelected();
            var alarmId = record.get("Alarm_id");
			Anynote.ajaxRequest({
						baseParams: {alarmId:alarmId},
						action: '${pageContext.request.contextPath}/heraldRecord_sendCount.action',
						callback: function(jsonResult){
						   var alarmTarget = [];
								var alarm = new Array();
						   var sj = jsonResult.datas ;
						   for(var i=0;i<sj.length;i++){
						     var alarm = new Array();
						     var al = sj[i];
						      alarm.push(al.name);
						      alarm.push(al.count);
						      alarmTarget.push(alarm);
						   }
								var accountListInOutStore = new Ext.data.ArrayStore({
							        fields: ['sendcount', 'herald'],
							        data: alarmTarget                     
							    });
								 // 拨打次数统计窗口
								var groupInOutWindow = new Ext.Window({
									title: '语音发送情况',
									width: 600,
									height: 350,
									modal: true,
									maximizable: false,
									resizable: false,
									layout:'fit',
									plain: true,
                                    iconCls: 'chart_bar',
									items: {
								    	xtype: 'columnchart',
							            store: accountListInOutStore,
							            yField: 'herald',
							            xField: 'sendcount',
							            xAxis: new Ext.chart.CategoryAxis({
							                title: '传报对象'
							            }),
							            yAxis: new Ext.chart.NumericAxis({
											maximum:50,
											minimum:0,
							                title: '拨打电话次数'
							            }),
							            extraStyle: {
							               xAxis: {
							                    labelRotation: 0
							                },
						                   yAxis: {
							                    labelRotation: 0
							                }
							            }
							        }
								}).show();
				}
				})
			};
	</script>
</head>
<body>
<div id="heraldRecordListDiv">
	<div id="heraldRecordListToolBarDiv"></div>
	<div id="heraldRecordListGridDiv" style="width:100%;height:100%;"></div>
</div>
</body>
</html>